#include "Deck.h"
#include <stdlib.h>
#include <time.h>


namespace core
{

Deck::Deck()
	: mCardsRest(NUM_OF_CARDS_IN_DECK)
{
	for (int i = 0; i < NUM_OF_CARDS_IN_DECK; i++)
		mCardsList[i] = IN_DECK;
}

Card Deck::deal_card()
{
	srand(time(0));

	int card_val = rand() % mCardsRest + 1;
	int counter(0);
	CARD_STATUS* it = mCardsList;
	while (counter != card_val)
		if (*it++ == IN_DECK) counter++;

	card_val = it - mCardsList;

	*(--it) = IN_HAND;
	mCardsRest--;

	uint8 rnk = card_val % 13;
	if (0 == rnk || 1 == rnk)
		rnk += 13;

	uint8 suit = (card_val - 1) / 13;
	return Card(rnk, suit);
}

void Deck::reset()
{
	for (int i = 0; i < NUM_OF_CARDS_IN_DECK; i++)
		mCardsList[i] = IN_DECK;
	mCardsRest = NUM_OF_CARDS_IN_DECK;
}

} // namespace core